package com.hst.capacity.infra.persistence.redis;

import com.hst.capacity.domain.repository.redis.AliTripRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

@Repository
public class AliTripRedisImpl implements AliTripRedis {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void writePriceRuleValue(String keySuffix, String value) {
        String key = String.format(ORDER_PRICE_KEY, keySuffix);
        redisTemplate.opsForValue().set(key, value, 600, TimeUnit.SECONDS);
    }

    @Override
    public String getPriceRuleValue(String keySuffix) {
        String key = String.format(ORDER_PRICE_KEY, keySuffix);
        String value = redisTemplate.opsForValue().get(key);
        return value;
    }

}
